package com.net.framework.help.dialog;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.net.framework.help.R;
import com.net.framework.help.utils.UIUtils;

/**
 * Author：xiaobin.zhang
 * Email：154722566@qq.com
 * Date：2017/8/1 14:29
 * Desc：<--图片识别弹出框，保存到手机，识别二维码-->
 */
public class ImageDiscernDialog implements View.OnClickListener {
    private CustomDialogBuilder dialogBuilder;
    private View view;
    private Context context;
    private ImageDiscernCallback imageDiscernCallback;

    private LinearLayout ll_share;
    private TextView tv_save;
    private LinearLayout ll_discern_qrcode;

    public ImageDiscernDialog(Context context, ImageDiscernCallback imageDiscernCallback) {
        this.context = context;
        this.imageDiscernCallback = imageDiscernCallback;
        this.dialogBuilder = new CustomDialogBuilder(context).builder();
        dialogBuilder.setDialogBackground(R.drawable.radius_white_bg_1dp);
        initView();
    }

    private void initView() {
        view = UIUtils.inflate(context, R.layout.dialog_image_discern);
        ll_share = (LinearLayout) view.findViewById(R.id.ll_share);
        tv_save = (TextView) view.findViewById(R.id.tv_save);
        ll_discern_qrcode = (LinearLayout) view.findViewById(R.id.ll_discern_qrcode);
        ll_share.setOnClickListener(this);
        tv_save.setOnClickListener(this);
        ll_discern_qrcode.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.ll_share) {
            imageDiscernCallback.onSendImage();
            dialogBuilder.dismiss();
        } else if (v.getId() == R.id.tv_save) {
            imageDiscernCallback.onSaveImage();
            dialogBuilder.dismiss();
        } else if (v.getId() == R.id.ll_discern_qrcode) {
            imageDiscernCallback.onDiscernQrcode();
            dialogBuilder.dismiss();
        }
    }


    public void showDiscernQrcodeView(boolean isShow) {
        if (isShow) {
            ll_discern_qrcode.setVisibility(View.VISIBLE);
        } else {
            ll_discern_qrcode.setVisibility(View.GONE);
        }
    }

    /***
     * 显示对话框
     */
    public void getShowDialog() {
        ll_share.setVisibility(View.GONE);
        ll_discern_qrcode.setVisibility(View.GONE);
        dialogBuilder.setDefault().setMessage("").setNewCustomView(view, context).isCancelableOnTouchOutside(true).show();
    }

    public interface ImageDiscernCallback {
        /**
         * 发送图片
         */
        void onSendImage();

        /**
         * 保存图片
         */
        void onSaveImage();

        /**
         * 识别二维码
         */
        void onDiscernQrcode();
    }
}
